/**
 * 
 */
/**
 * @requires OpenLayers/Layer.js
 * @requires OpenLayers/Layer/Image.js
 */
OpenLayers.Layer.ImageLayer = OpenLayers.Class(OpenLayers.Layer, {
	images: null,
	idimages: null,
	/**
     * Property: isBaseLayer
     * {Boolean} The layer is a base layer.  Default is true.  Set this property
     * in the layer options
     */
    isBaseLayer: false,
    /**
     * Property: aspectRatio
     * {Float} The ratio of height/width represented by a single pixel in the
     * graphic
     */
    aspectRatio: null,
    
	initialize: function(name, options) {
        OpenLayers.Layer.prototype.initialize.apply(this, arguments);
        this.images = [];
        this.idimages = {};
    },
    
    /**
     * Method: destroy
     * Destroy this layer
     */
    destroy: function() {
        if (this.images) {
        	for(var i in this.images){
        		var tile = this.images[i].tile;
        		if(tile){
        			this.images[i].removeTileMonitoringHooks(tile);
		            tile.destroy();
		            this.images[i].tile = null;
        		}
        	}
        	this.images = null;
        }
        if(this.idimages){
        	this.idimages = null;
        }
        OpenLayers.Layer.prototype.destroy.apply(this, arguments);
    },
    
    /**
     * Method: clone
     * Create a clone of this layer
     *
     * Paramters:
     * obj - {Object} An optional layer (is this ever used?)
     *
     * Returns:
     * {<OpenLayers.Layer.Image>} An exact copy of this layer
     */
    clone: function(obj) {
        
        if(obj == null) {
            obj = new OpenLayers.Layer.ImageLayer(this.name,
                                               this.getOptions());
        }

        //get all additions from superclasses
        obj = OpenLayers.Layer.prototype.clone.apply(this, [obj]);

        // copy/set any non-init, non-simple values here

        return obj;
    },
    
    
    /**
     * APIMethod: setMap
     * 
     * Parameters:
     * map - {<OpenLayers.Map>}
     */
    setMap: function(map) {
        OpenLayers.Layer.prototype.setMap.apply(this, arguments);
    },
    
    /** 
     * Method: moveTo
     * Create the tile for the image or resize it for the new resolution
     * 
     * Parameters:
     * bounds - {<OpenLayers.Bounds>}
     * zoomChanged - {Boolean}
     * dragging - {Boolean}
     */
    moveTo:function(bounds, zoomChanged, dragging) {
        OpenLayers.Layer.prototype.moveTo.apply(this, arguments);

        for(var i in this.images){
        	this.images[i].moveTo(bounds, zoomChanged, dragging);
        }
    },
    
    /**
     * 添加图片
     */
    addImage: function(img){
    	img.setMap(this.map);
    	img.layer = this;
    	this.images.push(img);
    	this.idimages[img.id] = img;
    	img.redraw();
    	this.div.appendChild(img.div);
    },
    
    /**
     * 删除image
     */
    removeImage: function(img){
    	img.removeMap(this.map);
    	img.layer = null;
    	img.map = null;
    	delete this.idimages[img.id];
    	OpenLayers.Util.removeItem(this.images, img);
    	this.div.removeChild(img.div);
    },
    
    CLASS_NAME: "OpenLayers.Layer.ImageLayer"
});